﻿using System;
using System.Windows.Forms;
using AppCommon.Framework;
using TMSIM.Client.CM.Business;
using TMSIM.Client.CM.UI.MainFrm;
using SysCommon;
using SysCommon.Interface.ManageUserSession;
using ESRI.ArcGIS;

namespace TMSIM.Client.CM
{
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        private static void Main()
        {
            SysCommon.Interface.InterfaceManager ifcMgr = null;
            try
            {
                ifcMgr = new SysCommon.Interface.InterfaceManager();

                ifcMgr.BuildRealizeClass();

                SysCommon.Global.InitSystemName();

                #region 登录窗体显示

                //try
                //{
                //    Global.mainLog.Debug("Main()方法中，开始调用IMUS_ManageUserSessionBizCtrl.ShowLogonFrom()");
                //    IMUS_ManageUserSessionBizCtrl m_mus = (IMUS_ManageUserSessionBizCtrl)
                //                                          SystemFactory.GetBizController(
                //                                              typeof(IMUS_ManageUserSessionBizCtrl));
                //    if (!m_mus.ShowLogonFrom()) return;
                //    Global.mainLog.Debug("Main()方法中，调用IMUS_ManageUserSessionBizCtrl.ShowLogonFrom()完成");
                //}
                //catch (Exception ex)
                //{
                //    Global.mainLog.Error("Main()方法中，调用IMUS_ManageUserSessionBizCtrl.ShowLogonFrom()方法出错", ex);
                //    SysCommon.MsgBox.SysMessageBox.ShowErrorMessageBox(null, "系统出错退出", false);
                //    return;
                //}

              
                #endregion

             

                //
                if (!RuntimeManager.Bind(ProductCode.Engine))
                {
                    if (!RuntimeManager.Bind(ProductCode.Desktop))
                    {
                        MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.");
                        return;
                    }
                }

                CMGlobal.mainfrm = new MainForm();
                try
                {
                    MainFormMDT m_MDT = new MainFormMDT();
                    m_MDT.TMSIMMainForm = CMGlobal.mainfrm;
                    m_MDT.init();
                }
                catch (Exception ex)
                {
                    SysCommon.Global.mainLog.Error("Program类中的MainFormMDT出错", ex);
                    SysCommon.MsgBox.SysMessageBox.ShowErrorMessageBox(null, "系统出错退出", false);
                }
                Application.Run(CMGlobal.mainfrm);
            }
            catch (Exception ex)
            {
                SysCommon.Tools.AutoLogHelper.Error(ex);
            }
            finally
            {
                if (ifcMgr != null)
                    ifcMgr.FreeRealizeClass();
            }
        }
    }
}